package com.wgl.springbootmap.controller;

import com.wgl.springbootmap.mapper.UserMapper;
import com.wgl.springbootmap.pojo.User;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.List;

/**
 * @author WANGguoli
 */
@RestController
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @GetMapping("/queryUserList")
    public List<User> queryUserList(){
        List<User> userList = userMapper.queryUserList();

        for(User user:userList){
            System.out.println(user);
        }

        return userList;
    }

    @GetMapping("/queryUserById")
    public User queryUserById(){

        User user = userMapper.queryUserById(1000);
        return user;



    }


    @GetMapping("/addUser")
    public void addUser(){
        userMapper.addUser(new User(1001,"ww","123456"));
        System.out.println("添加成功");

    }

    @GetMapping("/updateUser")
    public String updateUser(){
        userMapper.updateUser(new User(1,"秃驴","123465"));
        return "更改成功";
    }


    @GetMapping("/deleteUser")
    public String deleteUser(){
        userMapper.deleteUser(1);
        return "删除成功";

    }


}
